package com.zd.kids.ui.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.hyy.libray.common.BaseUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.core.CenterPopupView;
import com.zd.kids.DataBean.TestTrainWordResultDataBean;
import com.zd.kids.R;
import com.zd.kids.ui.activity.TrainResultActivity;

import java.util.List;

import androidx.annotation.NonNull;

/**
 * @ClassName: com.zd.kids.ui.view
 * @Description:
 * @Author: hyy
 * @Date: 2020/6/19
 * @Time: 10:21 AM
 */
public class TestWordRecordPopupWindow extends BasePopupView {
    Activity activity;
    String queName;
    ImageView img_tag;
    ImageView img_content;
    TextView tv_title;

    List<TestTrainWordResultDataBean> testTrainWordResultDataBeans;


    public TestWordRecordPopupWindow(@NonNull Activity context, List<TestTrainWordResultDataBean> testTrainWordResultDataBeans, String queName) {
        super(context);
        this.activity = context;
        this.queName = queName;

        this.testTrainWordResultDataBeans = testTrainWordResultDataBeans;
    }


    @Override
    protected void init() {
        super.init();
        img_tag = findViewById(R.id.img_tag);
        tv_title = findViewById(R.id.tv_title);
        img_content = findViewById(R.id.img_content);

        boolean isAiComplete = testTrainWordResultDataBeans==null;

        if (isAiComplete) {
            findViewById(R.id.tv_yy).setVisibility(VISIBLE);
            findViewById(R.id.tv_yy).setOnClickListener(view -> {
                activity.finish();
            });

            tv_title.setText(StringUtils.getString(R.string.inservation_two_tips));
            img_tag.setImageResource(R.mipmap.ic_complete_ai);
            img_content.setImageResource(R.mipmap.ic_complete2);
        }


        findViewById(R.id.ll_complete).setOnClickListener(view -> {
            if (!isAiComplete) {

                String result = new Gson().toJson(testTrainWordResultDataBeans);

                Intent intent = new Intent(activity, TrainResultActivity.class);
                intent.putExtra(TrainResultActivity.RESULT_DATA_KEY, result);
                intent.putExtra(TrainResultActivity.QUE_NAME_KEY, queName);
                activity.startActivity(intent);
            }


            activity.finish();
        });
    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.layout_complete_recoder;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.layout_complete_recoder;
    }


    public void showView() {
        new XPopup.Builder(getContext())
                .dismissOnTouchOutside(false)
                .dismissOnBackPressed(false)
                .asCustom(this)
                .show();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return true;
    }
}
